/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Campeonato;

import Time.Time;
import java.util.Random;
import javax.swing.JOptionPane;

/**
 *
 * @author Brüning
 */
public final class Embate {
    Time time1;
    Time time2;
    private int gol1;
    private int gol2;
    
public  Embate(Time time1, Time time2){
        this.time1=time1;
        this.time2=time2;
        
    }
 public Time geTime1(){
     return time1;
 }
    
 public Time geTime2(){
     return time2;
 }
    public void placar(){
        Random t1 = new Random(); Random t2 = new Random(); int meio1; int meio2;
        int ataque1; int ataque2;
        
        if (time1.media(time1.getMeio(), 1) > time2.media(time2.getMeio(), 1)) {
           meio1 = t1.nextInt(3); meio2 = t2.nextInt(2);
           }else{
            meio1 =t1.nextInt(2);  meio2 = t2.nextInt(3);   
            }
         ataque1 = meio1 + time1.media(time1.getAtq(), 2); 
         ataque2 = meio2 + time2.media(time2.getAtq(), 2);
          
         setGol1(ataque1 - time1.media(time1.getDef(), 0)-(meio2));
         setGol2(ataque2 - time2.media(time2.getDef(), 0)-(meio1));
               
        }
    public Time vitoria(){
        placar();
           JOptionPane.showMessageDialog(null, time1.getNome() + ": " + getGol1() +" "+ time2.getNome() + ": " + getGol2());
     
        if (gol1<gol2) 
            return  time2;
        
            if (gol1>gol2)
                return time1;
            else 
                time1.setPontos(1);
                time2.setPontos(1);
                return new Time("empate");
    }

    public int getGol1() {
        if (gol1<0) {
            return 0;
        }else
        return gol1;
    }

    public void setGol1(int gol1) {
        this.gol1 = gol1;
    }

    public int getGol2() {
        if (gol2<0) {
            return 0;
        }else
        return gol2;
    }

    public void setGol2(int gol2) {
        this.gol2 = gol2;
    }
    
    }
